package com.ling.pl.security.service;

import com.ling.pl.security.model.DefaultRole;
import com.ling.pl.system.service.DictionaryEntity;
import com.ling.pl.system.service.DictionaryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class AllRoleDictionaryGenerator implements DictionaryGenerator {

    @Autowired
    DefaultRoleService roleService;

    @Override
    public List<DictionaryEntity> getDictionaryEntities() {
        List<DefaultRole> roles = roleService.loadAllRoles();
        List<DictionaryEntity> results = new ArrayList<DictionaryEntity>();
        for (DefaultRole role : roles) {
            DictionaryEntity dictionaryEntity = new DictionaryEntity();
            dictionaryEntity.setCode(role.getName());
            dictionaryEntity.setName(role.getDesc());
            results.add(dictionaryEntity);
        }
        return results;
    }

    @Override
    public String getDictType() {

        return "ALLROLE";
    }

}
